'use strict';

//也可以这样写: ...controller('mainCtrl',['$scope',function($scope){}]);
angular.module('app').controller('positionCtrl',['$scope','$http','$state','$q','cache','$log',function($scope, $http, $state, $q, cache, $log){
   
    $scope.isLogin = !!cache.get('name');
    $scope.message = $scope.isLogin?'投个简历':'去登录';
    $http.get('/data/position.json?id='+$state.params.id).then(function(res){
        $scope.position = res.data;
       

        $http.get('/data/company.json?id='+res.data.companyId).then(function(res){
            $scope.com=res.data;
        });
    });

    $scope.go = function(){
        if($scope.isLogin){
            if($scope.message !=='已投递'){
                $http.post('data/handle.json',{
                id:$scope.position.id 
                }).then(function(resp){
                    $log.info(resp.data);
                    $scope.message = "已投递"
                })                
            }

        }else{
            $state.go('login');
        }
    }

}]);